package alik.notes.client.event.impl;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

import alik.notes.client.NotesTable;
import alik.notes.client.event.Events.NotesChangeHandler;
import alik.notes.shared.data.Note;
import alik.notes.shared.service.NotesService;
import alik.notes.shared.service.NotesServiceAsync;


public class NotesChangeHandlerImpl implements NotesChangeHandler {
	
	private NotesTable notesTable;
	
	public NotesChangeHandlerImpl(NotesTable notesTable) {
		this.notesTable = notesTable;
	}

	@Override
	public void notesChanged() {
		final AsyncCallback<List<Note>> asyncCallback = new AsyncCallback<List<Note>>() {
			@Override
			public void onFailure(Throwable caught) {
			}

			@Override
			public void onSuccess(List<Note> notes) {
				notesTable.set(notes);
			}
		};

		NotesServiceAsync notesService = GWT.create(NotesService.class);
		notesService.getNotes(asyncCallback);
	}
}
